<?
$r = "../";
require_once($r."_engine/header_nocache.php");
require_once($r."_engine/c_account.php");
require_once($r."_engine/c_resources_storage.php");
require_once($r."_engine/c_feed.php");


$account = GetActiveAccount();

$monitor = new CMonitor();
$monitor->LoadById($monitor_id);

if ($monitor->data["account_id"] != $account->id) die("Access denied"); //TODO


$rs = new CResStorage();
$rs->LoadById($resource_id);


$str_monitor_url = normalize_url($monitor->data["url"]);

$ap1 = '<span class="selectedLink">';
$ap2 = '</span>';
if ($resource_prev_id > 0 && !$is_prev_fake)
{
	$ap1 = '<a href="history_nav.php'.
		'?monitor_id='.$monitor_id.
		'&resource_id='.$resource_prev_id.
		'&do_hl='.@$do_hl.
        '&dhl_type='.@$dhl_type.
		'" target="_parent" class="linkArrows">';
	$ap2 = '</a>';
}

$an1 = '<span class="selectedLink">';
$an2 = '</span>';
if ($resource_next_id > 0)
{
	$an1 = '<a href="history_nav.php'.
		'?monitor_id='.$monitor_id.
		'&resource_id='.$resource_next_id.
		'&do_hl='.@$do_hl.
        '&dhl_type='.@$dhl_type.
		'" target="_parent" class="linkArrows">';
	$an2 = '</a>';
}

$str_link_change_hl = 'history_nav.php'.
	'?monitor_id='.$monitor_id.
	'&resource_id='.$resource_id.
	'&do_hl='.($do_hl ? '0' : '1').
    '&dhl_type='.$dhl_type;

$str_link_view_changes_hl_1 = '<span class="selectedLink">';
$str_link_view_changes_hl_2 = '</span>';
if ($dhl_type != DHL_TYPE_ALL_PAGE)
{
    $str_link_view_changes_hl_1 = '<a href="history_nav.php'.
    	'?monitor_id='.$monitor_id.
    	'&resource_id='.$resource_id.
    	'&do_hl='.$do_hl.
        '&dhl_type='.DHL_TYPE_ALL_PAGE.
		'" target="_parent">';
    $str_link_view_changes_hl_2 = '</a>';
}

$str_link_view_changes_sum_1 = '<span class="selectedLink">';
$str_link_view_changes_sum_2 = '</span>';
if ($dhl_type != DHL_TYPE_ONLY_CHANGES_SUMMARY)
{
    $str_link_view_changes_sum_1 = '<a href="history_nav.php'.
    	'?monitor_id='.$monitor_id.
    	'&resource_id='.$resource_id.
    	'&do_hl='.$do_hl.
        '&dhl_type='.DHL_TYPE_ONLY_CHANGES_SUMMARY.
		'" target="_parent">';
    $str_link_view_changes_sum_2 = '</a>';
}


/* Calendar navigator at the top of the page */
$dt = $rs->data["download_dt"];
$str_calendar_date = date("M, Y", $dt);

GetCalendarForDownload($monitor_id, $resource_id, $dt,
    $prev, $list, $next);

$str_calendar_link_prev_1 = '<span class="selectedLink" style="font-size: 120%;">';
$str_calendar_link_prev_2 = '</span>';
if ($prev)
{
	$str_calendar_link_prev_1 = '<a href="history_nav.php'.
		'?monitor_id='.$monitor_id.
		'&resource_id='.$prev["id"].
		'&do_hl='.@$do_hl.
        '&dhl_type='.@$dhl_type.
		'" target="_parent" style="font-size: 120%;">';
	$str_calendar_link_prev_2 = '</a>';
}

$str_calendar_link_next_1 = '<span class="selectedLink" style="font-size: 120%;">';
$str_calendar_link_next_2 = '</span>';
if ($next)
{
	$str_calendar_link_next_1 = '<a href="history_nav.php'.
		'?monitor_id='.$monitor_id.
		'&resource_id='.$next["id"].
		'&do_hl='.@$do_hl.
        '&dhl_type='.@$dhl_type.
		'" target="_parent" style="font-size: 120%;">';
	$str_calendar_link_next_2 = '</a>';
}


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<meta name="generator" content="hand make">
	<!--link rel="stylesheet" type="text/css" href="http://localhost/w3monitor2/css/nav.css"-->
</head>

<style type="text/css">
a {
    color: white;
}
.text {
	font-family: Trebuchet MS, Verdana, sans-serif;
	font-size: 75%;
    color: white;
}
.monitorName {
	font-family: Trebuchet MS, Verdana, sans-serif;
	font-size: 120%;
    font-weight: bold;
    color: #C6F5FF;                   
}
.selectedLink {
    color: #D0DDDD;
}
.linkArrows {
	color: #FFCC00;
	text-decoration: none;
}
.selectedNumber {
	font-size: 140%;
	color: #FFCC00;
}	
</style>

<body leftmargin=0 topmargin=0 rightmargin=0 background="<?=$r?>images/nav_bg.gif">

<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%" 
    style="padding-left: 10; padding-right: 5; padding-top: 0;">
<tr>
    <td colspan="3">

<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">
<tr>
    <td width="100">

<p class="text" style="white-space: nowrap;">
	<a href="<?=$r?>members/dashboard.php" class="aStd" target="_parent">Back to Dashboard</a>
</p>

    </td>
    <td align="center">

<p class="text" style="white-space: nowrap;">
<?=$str_calendar_date?>
&nbsp;
<?=$str_calendar_link_prev_1?>&laquo;<?=$str_calendar_link_prev_2?>
&nbsp;
<?
foreach ($list as $d => $v)
{
    $s1 = '<span class="selectedLink">';
    $s2 = '</span>';
    
    if ($v)
    {
     	$href = 'history_nav.php'.
    		'?monitor_id='.$monitor_id.
    		'&resource_id='.$v["id"].
    		'&do_hl='.@$do_hl.
            '&dhl_type='.@$dhl_type;
        
        if (/*$v["id"] == $resource_id*/
			$d == date("j", $rs->data["download_dt"]))
        {
            // Currently selected item
            $s1 = '<span class="selectedNumber">';
            $s2 = '</span>';
        }
        else if ($v["resource_status"] == RESOURCE_STORAGE_STATUS_TRIGGERED)
        {
            $s1 = '<a href="'.$href.'" target="_parent" style="color: #FFCC00;">';
            $s2 = '</a>';
        }
        else if ($v["resource_status"] == RESOURCE_STORAGE_STATUS_CHANGED)
        {
            $s1 = '<a href="'.$href.'" target="_parent" style="color: #D0DDDD;">';
            $s2 = '</a>';
        }
        else if ($v["resource_status"] == RESOURCE_STORAGE_STATUS_NOT_CHANGE)
        {
            $s1 = '<a href="'.$href.'" target="_parent" style="color: white;">';
            $s2 = '</a>';
        }
        else if ($v["resource_status"] == RESOURCE_STORAGE_STATUS_ERROR)
        {
            $s1 = '<a href="'.$href.'" target="_parent" style="color: red;">';
            $s2 = '</a>';
        }
        else
        {
        }
    }
    
    echo $s1.$d.$s2.' &nbsp; ';
}
?>
<?=$str_calendar_link_next_1?>&raquo;<?=$str_calendar_link_next_2?>
</p>

    </td>
    <td align="right" width="100">

<table border="0" cellspacing="0" cellpadding="0">
<tr><td valign="middle">
	<p class="text" style="padding-right: 6;">
    <a href="<?=$str_monitor_url?>" target="_parent">Close</a>
</td><td>
	<a href="<?=$str_monitor_url?>" target="_parent">
	<img src="../images/nav_close.gif" width="17" height="15" alt="" border="0" style="margin-top: 6;">
	</a>
</td></tr>
</table>

    </td>
</tr>
</table>

    </td>
</tr>
<tr>
    <td width="240">

<p class="monitorName">
    <?php echo domain_name_from_url($monitor->data["url"]); ?>
</p>

    </td>
    <td rowspan="2">

<table border="0" cellspacing="0" cellpadding="0" style="margin-top: 0;" align="center">
<tr height="35">
	<td width="5" style="background: url(../images/nav_panel_l.gif); background-repeat: no-repeat;">
    </td>
	<td style="background: url(../images/nav_panel_bg.gif);">
        <p class="text" style="padding-left: 5; font-weight: bold; white-space: nowrap;">
        <?=$ap1?>&lt;-- prev<?=$ap2?>
        </p>
    </td>
	<td style="background: url(../images/nav_panel_bg.gif)">
        <p align="center" class="text" style="font-weight: bold; color: #D5D6DA; padding-left: 20; padding-right: 20; white-space: nowrap;">
            Monitored <?=get_last_monitored_time_str($rs->data["download_dt"])?>.
            <?=$rs->GetScanResult()?>
        </p>
    </td>
	<td style="background: url(../images/nav_panel_bg.gif)">
        <p class="text" style="padding-right: 5; font-weight: bold; white-space: nowrap;">
        <?=$an1?>next --&gt;<?=$an2?>
        </p>
    </td>
	<td width="5" style="background: url(../images/nav_panel_r.gif); background-repeat: no-repeat;">
    </td>
</tr>
<tr>
	<td colspan="3" align="center">
<p class="text">
<input type="checkbox" <?=(@$do_hl ? 'checked' : '')?> onClick="onDoHl();">
Highlight
<span id="hl_ex"><span id="hl_ex2">changes</span></span>
and
<span id="hl_exi"><span id="hl_exi2">keywords</span></span>
</p>
    </td>
</tr>
</table>

    </td>
    <td width="240">
    </td>
</tr>
<tr>
    <td>
<p class="text" style="white-space: nowrap;">
    [ <?=$str_link_view_changes_hl_1?>Changes Highlighted<?=$str_link_view_changes_hl_2?> | <?=$str_link_view_changes_sum_1?>Changes Summary<?=$str_link_view_changes_sum_2?> ]
</p>
    </td>
    <td align="right">

<?php
$str_href_to_feed = get_link_to_feed($monitor);
if ($str_href_to_feed) {
?>
<table>
<tr>
	<td><p class="text" style="padding-right: 10;"><a href="<?=$str_href_to_feed?>">Subscribe</a></p></td>
	<td><a href="<?=$str_href_to_feed?>"><img src="../images/feed.gif" width="16" height="16" alt="" border="0"></a></td>
</tr>
</table>
<?php } ?>

    </td>
</tr>
</table>



<form name="f">
<input type="Hidden" name="f_highlight_font_color" value="<?=@$monitor->data["highlight_font_color"]?>">
<input type="Hidden" name="f_highlight_bk_color" value="<?=@$monitor->data["highlight_bk_color"]?>">
<?
$v = @$monitor->data["highlight_font_style"];
foreach ($g_highlight_font_style_map as $k => $name) 
{ 
	echo '<input type="Hidden" name="f_hl_fs_'.$k.'" value="'.($v & $k ? "1" : "").'"';
	echo '>'."\n";
} 
?>
</form>

<script language="javascript" type="text/javascript" src="<?=$r?>js/main.js">
</script>
<script language="javascript" type="text/javascript">
function update_hl_ex()
{
	var f = document.f;
	update_highlight_example(
		"hl_ex", "hl_ex2", "hl_exi", "hl_exi2",
		f.f_highlight_font_color.value, f.f_highlight_bk_color.value,
		f.f_hl_fs_1.value, f.f_hl_fs_2.value, f.f_hl_fs_4.value, f.f_hl_fs_8.value
	);
}
update_hl_ex();

function onDoHl()
{
	var u = '<?=$str_link_change_hl?>';
	window.parent.location = u;
}
</script>

</body>
</html>
